// 引入接口文件
import {  getProgresConstruction, delProgresConstruction, generateQRCode} from './progresConstructionServ.js'

// 对象和JSON字符串互转
import { parse } from 'qs'
// 弹出消息框
import { message } from 'antd'
// 日期处理对象
import moment from 'moment'
/* isEmpty 对象是否为空
 * isArray 对象是否数组
 * cloneDeep 对象深拷贝
 */
import { isEmpty, isArray, cloneDeep, merge } from 'lodash'
// 引入路由对象
import { hashHistory } from 'dva/router'
import { makeAddress } from "utils/util"
import { download } from '../../../../../utils/util.js';
//打包文件到压缩包
// import JSZip from 'jszip';
// import saveAs from 'file-saver';
// import $ from 'jquery';

// import toZip from 'utils/jszip'

// import toZip from '../../../../../utils/jszip'


// 初始默认状态
const defultState = {
        loading: false,
        btnLoading: false,
        biz: {
            queryForm: {}
        },
        progresConstruction: {},
        currentImg: '',
        currentItem: {},
        productId: '',
        qrcodeCount: '',
        codeId: '',
        channelId: '',
        channelType: [],
        zysqList: [],
        showAdv: null,
        qrcode:'',
        zysqUrl: `subPackages\/pages\/buildingDetail\/buildingDetail`
            
    }
    // 声明module
const tmpModule = {
    namespace: 'baseinfoModel',
    state: cloneDeep(defultState),
    subscriptions: {
        setup({ dispatch, history }) {
            history.listen(({ pathname, query }) => {
                if ('' + tmpModule.pathname === '' + pathname) {
                    dispatch({ type: 'updateStore', payload: cloneDeep(defultState) });
                }
            })
        },
    },
    // 方法列表
    effects: {
        * getProgresConstruction({ payload }, { put, call, select }) {
            const { data, success } = yield call(getProgresConstruction, payload);
            if (success) {
                let community = data
                yield put({ type: 'updateStore', payload: { community } })
            }
        },
        * deleteProgresConstruction({ payload }, { put, call, select }) {
                try {
                    const { data, success } = yield call(delProgresConstruction, payload);
                    let defultState = yield select(state => state[tmpModule.namespace])
                    if (success) {
                        message.success('删除成功', () => {
                            defultState.biz.refreshListDatas(true)
                        })
                    } else {

                    }
                } catch (e) {

                }
        },
        * qrcodeCreate({ payload }, { put, call, select }) {
            try {
                const { data, success } = yield call(generateQRCode, payload);
                if (success) {
                    console.log(data)
                    let qrcode = data
                    yield put({ type: 'updateStore', payload: { qrcode } })
                    message.success('小程序码生成成功', () => {
                        defultState.biz.refreshListDatas(true)
                    })
                }
            } catch (e) {

            }
        }
    },



    // 存入状态机
    reducers: {
        updateStore(preState, action) {
            return {...preState, ...action.payload };
        }
    }
}

export default tmpModule